package com.webservice_springboot.server.random_int;

import cn.hutool.core.util.NumberUtil;
import org.springframework.stereotype.Service;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

/**
 * 获取随机数字服务
 */
@Service
@WebService
public class RandomIntInterfaceImpl implements RandomIntInterface {
    private final int[] ARR = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    @Override
    @WebMethod(operationName = "queryRandomIntArr")
    @WebResult(name = "resArr")
    public int[] queryRandomIntArr(@WebParam(name = "length") int length) throws Exception {
        if (length <= 0) {
            return new int[0];
        }
        final int[] result = new int[length];
        for (int i = 0; i < length; i++) {
            result[i] = ARR[NumberUtil.generateRandomNumber(0, 9, 1)[0]];
        }
        return result;
    }
}
